const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const { CleanWebpackPlugin } = require('clean-webpack-plugin')

const webpack = require('webpack')

module.exports = {
  mode: 'development',
  devtool: 'eval',
  devServer: {
    static: {
        directory: path.join(__dirname, './dist')
    },
    open: true,
    hot: true
  },
  entry: './src/index.js',
  output: {
    filename: 'bundle.js',
    path: path.resolve(__dirname, './dist')
  },
  module: {
    rules: [
      {
        test: /\.js$/,
        loader: 'babel-loader',
        exclude: /node_modules/
      }
    ]
  },
  plugins: [
    new HtmlWebpackPlugin({
      template: './src/index.html'
    }),
    new CleanWebpackPlugin(), // 在每次打包之前都会删除上一次打包的文件
    new webpack.HotModuleReplacementPlugin() // 更新之后就不会刷新
  ]
}
